package leedcode;

/**
 * @description:
 * @author: zk
 * @date: 2023-02-08 20:26
 */
public class Question_202 {
    private static final int HAPPY_NUM = 1;

    public static boolean isHappy(int n) {
        // 替换为它每个位置
        String num = String.valueOf(n);
        // 平方
        char[] chars = num.toCharArray();
        int result = 0;
        for (char numChar : chars) {
            result += Math.pow(Double.parseDouble(String.valueOf(numChar)),2);
        }
        return HAPPY_NUM == result ? true : isHappy(result);
    }

    public static void main(String[] args) {
        System.out.println(isHappy(10));
    }

}
